home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Sources) / Standard Controls / Text / XGStdStaticText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-24  |  4.7 KB  |  208 lines

  1. /*    XGStdStaticText.cpp
  2.  *
  3.  *        this is my internal implementation of a static text object.
  4.  *    This is something I simply roll myself
  5.  */
  6.  
  7. /*  YAAF - Yet another application framework
  8.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  9.  *  
  10.  *  This library is free software; you can redistribute it
  11.  *  and/or modify it under the terms of the GNU Library
  12.  *  General Public License as published by the Free Software
  13.  *  Foundation; either version 2 of the License, or any
  14.  *  later version.
  15.  *  
  16.  *  This library is distributed in the hope that it will be
  17.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  18.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  19.  *  PURPOSE. See the GNU Library General Public License for
  20.  *  more details.
  21.  *  
  22.  *  You should have received a copy of the GNU Library General
  23.  *  Public License along with this library; if not, write to the
  24.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25.  *  Boston, MA 02111-1307, USA.
  26.  *  
  27.  *  To contact the author, either e-mail me at
  28.  *  woody@alumni.caltech.edu, or write to us at
  29.  *  
  30.  *          William Edward Woody
  31.  *          In Phase Consulting
  32.  *          1545 Ard Eevin Avenue
  33.  *          Glendale, CA 91202
  34.  */
  35.  
  36. #include <string.h>
  37. #include <XError.h>
  38. #include <XStdText.h>
  39. #include <XApplication.h>
  40. #include <XStdControls.h>
  41. #include <XDataUtil.h>
  42.  
  43. /************************************************************************/
  44. /*                                                                        */
  45. /*    Construction/Destruction                                            */
  46. /*                                                                        */
  47. /************************************************************************/
  48.  
  49. /*    XGStdStaticText::XGStdStaticText
  50.  *
  51.  *        Initialize me
  52.  */
  53.  
  54. XGStdStaticText::XGStdStaticText(XGView *v, XGArgStream &s) : 
  55.     XGStdText(v,s,true)
  56. {
  57.     char buffer[256];
  58.     s.GetString(sizeof(buffer),buffer);
  59.     Init(buffer);
  60. }
  61.  
  62. XGStdStaticText::XGStdStaticText(XGView *v, XGSTextInitRecord &s) : 
  63.     XGStdText(v,s.v,true)
  64. {
  65.     Init(s.text);
  66. }
  67.  
  68. /*    XGStdStaticText::~XGStdStaticText
  69.  *
  70.  *        Delete me
  71.  */
  72.  
  73. XGStdStaticText::~XGStdStaticText()
  74. {
  75. }
  76.  
  77. /************************************************************************/
  78. /*                                                                        */
  79. /*    Text Drawing                                                        */
  80. /*                                                                        */
  81. /************************************************************************/
  82.  
  83. /*    XGStdStaticText::GetText
  84.  *
  85.  *        Get the text contents of this
  86.  */
  87.  
  88. void XGStdStaticText::GetText(char *text)
  89. {
  90. #if OPT_MACOS == 1
  91.     strcpy(text,fString.Get());
  92. #endif
  93.  
  94. #if OPT_WINOS == 1
  95.     ::GetWindowText(_GetHWND(),text,256);
  96. #endif
  97. }
  98.  
  99. /*    XGStdStaticText::SetText
  100.  *
  101.  *        Set the text and force a redraw
  102.  */
  103.  
  104. void XGStdStaticText::SetText(char *text)
  105. {
  106. #if OPT_MACOS == 1
  107.     fString = text;
  108. #endif
  109.  
  110. #if OPT_WINOS == 1
  111.     ::SetWindowText(_GetHWND(),text);
  112. #endif
  113.  
  114.     InvalView();
  115. }
  116.  
  117. /************************************************************************/
  118. /*                                                                        */
  119. /*    Static Control Drawing                                                */
  120. /*                                                                        */
  121. /************************************************************************/
  122.  
  123. /*    XGStdStaticText::DoDrawView
  124.  *
  125.  *        Draw this thing
  126.  */
  127.  
  128. void XGStdStaticText::DoDrawView(Rect)
  129. {
  130. #if OPT_MACOS == 1
  131.     XGDraw draw(this);
  132.     Rect r;
  133.     const char *text = fString.Get();
  134.     
  135.     r = GetContentRect();
  136.     
  137.     ::TextFont(fFont);
  138.     ::TextSize(fSize);        // request my current font
  139.     ::EraseRect(&r);
  140.     ::TETextBox(text,strlen(text),&r,teFlushDefault);
  141. #endif
  142. }
  143.  
  144. /************************************************************************/
  145. /*                                                                        */
  146. /*    Static Control Drawing                                                */
  147. /*                                                                        */
  148. /************************************************************************/
  149.  
  150. /*    XGStdStaticText::Init
  151.  *
  152.  *        This handles the initialization
  153.  */
  154.  
  155. void XGStdStaticText::Init(char *buffer)
  156. {
  157.     long l;
  158.     
  159.     l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
  160. #if OPT_MACOS == 1
  161.     fFont = GETHIWORD(l);
  162.     fSize = GETLOWORD(l);
  163.     fString = buffer;
  164. #endif
  165.  
  166. #if OPT_WINOS == 1
  167.     Rect r;
  168.     HWND w;
  169.     
  170.     /*
  171.      *    Get the location of the control in the parent's coordinate
  172.      *    system
  173.      */
  174.      
  175.     r = GetContentRect();
  176.     if (GetParent()) {
  177.         ViewToGlobal(&r);
  178.         GetParent()->GlobalToView(&r);
  179.     }
  180.     
  181.     /*
  182.      *    Create the control window
  183.      */
  184.     
  185.     w = CreateWindow("EDIT",                    // control class
  186.                      buffer,                    // control title
  187.                      WS_CHILD | ES_AUTOHSCROLL | // control window flags
  188.                          ES_READONLY,
  189.                      r.left,
  190.                      r.top,
  191.                      r.right-r.left,
  192.                      r.bottom-r.top,            // control location
  193.                      GetParent()->_GetHWND(),    // container window
  194.                      NULL,                        // no menu
  195.                      _GInstance,                // My app instance
  196.                      NULL);                        // no additional args
  197.     if (w == NULL) {
  198.         throw XPostError("Unable to make display box");
  199.     }
  200.     
  201.     _SetHWND(w);                                // set me as the window
  202.     SetProp(w,_GViewClass,(HANDLE)this);
  203.     if (IsVisible()) ShowWindow(w,SW_SHOW);
  204.     EnableWindow(w,IsEnabled());                // set me up
  205. #endif
  206. }
  207.  
  208.